// import Vue from 'vue'
import App from './App.vue'
// import Home from './pages/home'
import View from './pages/view'
import Form from './pages/form'
import Stat from './pages/stat'
import NotFound from './pages/notFind'
import { getI18n } from './services/lang'
import editorRegister from 'components/form-rich-editor/register'

const Vue = window.Vue
const VueRouter = window.VueRouter

Vue.config.productionTip = false
const statTitle = encodeURIComponent("统计")

getI18n(window.appNameEn).then(res => {
  window.i18nLang = res && res.datas || {}
})

const routes = [{
  name: 'home',
  path: '/', component: App,
  children: [{
    path: `/subpage/:name`, component: Stat
  }, {
    path: `/form/${statTitle}`, component: Stat
  }, {
    path: '/grid/:name', component: View
  }, {
    path: '/form/:name', component: Form
  }]
},{
  path: "*",
  component: NotFound
}]

// 3. 创建 router 实例，然后传 `routes` 配置
// 你还可以传别的配置参数, 不过先这么简单着吧。
const router = new VueRouter({
  routes // (缩写) 相当于 routes: routes
})

let menuAddActive = function(menu, name){
  menu.forEach(element => {
    if(element.title === name){
      element.active = true
    }else if(element.sub){
      menuAddActive(element.sub, name)
    }
  })
}

router.afterEach((to) => {
  if(window.menu){
    menuAddActive(window.menu, to.params.name)
  }
  // console.log(from,"from")
  Vue.nextTick(() => {
    BH_UTILS.setContentMinHeight($(".sc-container"), "", 67)
  })
})

const vm = new Vue({
  template: '<router-view></router-view>',
  router
}).$mount()

editorRegister(vm)

document.body.appendChild(vm.$el)
